﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CPPEI.Coolzon.Metadata;
using CPPEI.Coolzon.UI;
using CPPEI.Coolzon.UI.Views;
using CPPEI.Coolzon.UI.Data;

namespace CPPEI.Coolzon.BrowserApp.MainViewControl
{
    /// <summary>
    /// SceneNavigation.xaml 的交互逻辑
    /// </summary>
    public partial class SceneNavigation:UserControl
    {
        public Solution solution { get; set; }

        public Label CurrentLable;
        public SceneNavigation()
        {
            InitializeComponent();
        }

        public void BindScene()
        {
            if (solution == null) return;
            foreach (Scene scene in solution.Scenes)
            {
                Label lbl = new Label();
                lbl.Name = scene.Name;
                lbl.Content = scene.Caption;
                lbl.MouseLeftButtonDown += lbl_Click;
                lbl.DataContext = scene;
                lbl.Style = (Style)spLayout.Resources["lblEnter"];
                spLayout.Children.Add(lbl);
            }
        }

        private string LastSelectedName = string.Empty;
        void lbl_Click(object sender, RoutedEventArgs e)
        {
            Label lbl = sender as Label;
            if (lbl == CurrentLable) return;

            Scene scene = lbl.DataContext as Scene;
            Event.Core.CoreEventBus.Publish(new Event.Core.CoreOpenSceneEvent(SwitchMode.Replace, "", scene.Name, null));

            lbl.Style = (Style)spLayout.Resources["lblPress"];
            if (CurrentLable != null)
            {
                CurrentLable.Style = (Style)spLayout.Resources["lblEnter"];
            }
            CurrentLable = lbl;
        }
    }
}
